package com.nbot.server.controller;

import com.nbot.server.annotation.Log;
import com.nbot.server.domain.KeyParameterMonthDO;
import com.nbot.server.service.KeyParameterMonthService;
import com.nbot.server.util.PageUtils;
import com.nbot.server.util.Query;
import com.nbot.server.util.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 重要参数每月归档汇总
 *
 * @author nbot
 * @email nbot@163.com
 * @date 2018-06-21 09:36:03
 */

@Controller
@RequestMapping("/server/keyParameterMonth")
public class KeyParameterMonthController {
    @Autowired
    private KeyParameterMonthService keyParameterMonthService;

    @GetMapping()
    @RequiresPermissions("server:keyParameterMonth:keyParameterMonth")
    String KeyParameterMonth() {
        return "server/keyParameterMonth/keyParameterMonth";
    }

    @ResponseBody
    @Log("查看重要参数每月归档汇总")
    @GetMapping("/list")
    @RequiresPermissions("server:keyParameterMonth:keyParameterMonth")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<KeyParameterMonthDO> keyParameterMonthList = keyParameterMonthService.list(query);
        int total = keyParameterMonthService.count(query);
        PageUtils pageUtils = new PageUtils(keyParameterMonthList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("server:keyParameterMonth:add")
    String add() {
        return "server/keyParameterMonth/add";
    }

    @GetMapping("/edit/{autoId}")
    @RequiresPermissions("server:keyParameterMonth:edit")
    String edit(@PathVariable("autoId") Long autoId, Model model) {
        KeyParameterMonthDO keyParameterMonth = keyParameterMonthService.get(autoId);
        model.addAttribute("keyParameterMonth", keyParameterMonth);
        return "server/keyParameterMonth/edit";
    }

    /**
     * 保存
     */
    @Log("保存重要参数每月归档汇总")
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("server:keyParameterMonth:add")
    public R save(KeyParameterMonthDO keyParameterMonth) {
        if (keyParameterMonthService.save(keyParameterMonth) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @Log("修改重要参数每月归档汇总")
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("server:keyParameterMonth:edit")
    public R update(KeyParameterMonthDO keyParameterMonth) {
        keyParameterMonthService.update(keyParameterMonth);
        return R.ok();
    }

    /**
     * 删除
     */
    @Log("删除重要参数每月归档汇总")
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("server:keyParameterMonth:remove")
    public R remove(Long autoId) {
        if (keyParameterMonthService.remove(autoId) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @Log("批量删除重要参数每月归档汇总")
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("server:keyParameterMonth:batchRemove")
    public R remove(@RequestParam("ids[]") Long[] autoIds) {
        keyParameterMonthService.batchRemove(autoIds);
        return R.ok();
    }

}
